#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
static char *program="";
void usage()
{
printf("%s:\n"
       "-s    server ip address\n"
       "-p    dest port\n"
       "-h    help info\n",program);
       exit(-1);
}
char send_buf[40960];
int main(int argc,char *argv[])
{
    struct sockaddr_in remote_addr;
    char *ip=NULL;
    char *port=NULL;
    int opt;
    program=argv[0];
    if(argc<2){
        usage();
    }
    while(-1!=(opt=getopt(argc,argv,"s:p:h"))){
        switch(opt){
            case 's':
                ip=optarg;
                break;
            case 'p':
                port=optarg;
                break;
            case 'h':
            case '?':
                usage();
                break;
        }
    }
    if(NULL==ip||NULL==port){
        usage();
    }
    remote_addr.sin_family=AF_INET;
    remote_addr.sin_addr.s_addr=inet_addr(ip);
    remote_addr.sin_port=htons(atoi(port));
    int fd=socket(PF_INET,SOCK_STREAM,0);
    int yes=1;
    setsockopt(fd,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(yes));
    int ret=bind(fd,(struct sockaddr*)&remote_addr,sizeof(struct sockaddr_in));
    if(ret<0){
        printf("bind failed\n");
        return -1;
    }
    listen(fd,5);
    socklen_t len;
    struct sockaddr_in client_addr;
    int conn=accept(fd,(struct sockaddr*)&client_addr,&len);
    int i=0;
    for(i=0;i<30000;i++){
        send_buf[i]='a';
    }
    send_buf[i]=0;
    int send_size=i;
    int sended=send(conn,send_buf,send_size,0);
    printf("send=%d\n",sended);
}
